# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
#   cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
#   Mayor.create(:name => 'Daley', :city => cities.first)

Enterprise.create! [ {
    :name => '海南微斯达',
    :address => '海南DC城3楼111',
    :email => 'amon.lei@21cn.com',    
    :qq => '78616848 151430712',
    :fax => '089866777777',
    :link_phone => '089831669989',
    :synopsis => '主营皮卡，五十铃中小型货车'
  },{
    :name => '海南东里房地产',
    :address => '半山花园海天阁1668',
    :email => 'amon.lei@gmail.com',
    :qq => '78616848 ',
    :fax => '089866777777',
    :link_phone => '089831669989',
    :synopsis => '主营别墅，商住楼 '
  }]
[{
    :enterprise_id => Enterprise.first.id,
    :full_name => '雷宇',
    :mobile => '13976118662',
    :password => '1234',
    :email => 'amon.lei@gmail.com',
    :status => 'active'
  },{
    :enterprise_id => Enterprise.first.id,
    :full_name => '刘柳',
    :mobile => '139766666666',
    :password => '1234',
    :email => 'liuliu@gmail.com',
    :status => 'active'
  },{
    :enterprise_id => Enterprise.all[1].id,
    :full_name => '雷宇',
    :mobile => '13976118662',
    :password => '1234',
    :email => 'amon.lei@gmail.com',
    :status => 'active'
  }].each do |attributes|
  User.create! attributes, :as => :admin
end

Enterprise.first.update_attributes! :admin_id => User.first
Enterprise.all[1].update_attributes! :admin_id => User.all[1]

Thread.current[:current_user_id] = User.first.id


Group.create! [{
    :name => '办公室',
    :enterprise_id => Enterprise.all[0].id
  },{
    :name => '经理',
    :enterprise_id => Enterprise.all[0].id
  }]
User.all[0].groups = [Group.all[0],Group.all[1]]
User.all[1].groups = [Group.all[1]]

# customers
Customer.create! [{
		:first_name => '刘',
		:last_name => '晓明',
		:title => '市场总监',
		:organization => '海南省新兴电子信息产业有限公司',
		:background_info => '通过省信产局副主任张小泉介绍认识',
		:visible_scope => 'users'
	}, {
		:first_name => '陈',
		:last_name => '真',
		:title => '总经理',
		:organization => '海口市美晨金融咨询服务公司',
		:background_info => '客户通过网站找到我们，并给我打了电话咨询有关公司业务，并十分感兴趣，希望建立长期合作关系'	,
		:visible_scope => 'groups'
	}
]

Customer.all[0].users = User.where(:enterprise_id => Enterprise.current)
Customer.all[1].users = User.where(:enterprise_id => Enterprise.current)

Customer.all[0].groups = Group.where(:enterprise_id => Enterprise.current)
Customer.all[1].groups = Group.where(:enterprise_id => Enterprise.current)

ContactWay::Phone.create! [ {
		:customer_id => Customer.first.id,
		:way => '0898-66715502',
		:type_name => '工作'
	}, {
		:customer_id => Customer.first.id,
		:way => '13976118862',
		:type_name => '私人'
	}, {
		:customer_id => Customer.first.id,
		:way => '0898-31551168',
		:type_name => '家庭'
	},{
		:customer_id => Customer.all[1].id,
		:way => '0898-66713502',
		:type_name => '工作'
	}, {
		:customer_id => Customer.first.id,
		:way => '13976118262',
		:type_name => '私人'
	}, {
		:customer_id => Customer.all[1].id,
		:way => '0898-31851168',
		:type_name => '家庭'
	}
]

ContactWay::Email.create! [ {
		:customer_id => Customer.first.id,
		:way => 'liuxiaoming@gmail.com',
		:type_name => '工作'
	}, {
		:customer_id => Customer.first.id,
		:way => 'liuxiaoming@163.com',
		:type_name => '私人'
	}, {
		:customer_id => Customer.all[1].id,
		:way => 'chen.zhen@gmail.com',
		:type_name => '工作'
	}, {
		:customer_id => Customer.first.id,
		:way => 'chen.zhen@126.com',
		:type_name => '私人'
	}
]

ContactWay::Im.create! [ {
		:customer_id => Customer.first.id,
		:way => '7866618',
		:type_name => 'QQ'
	}, {
		:customer_id => Customer.first.id,
		:way => 'liuxiaoming@163.com',
		:type_name => 'MSN'
	}, {
		:customer_id => Customer.all[1].id,
		:way => '35887787',
		:type_name => 'QQ'
	}, {
		:customer_id => Customer.first.id,
		:way => 'chen.zhen@126.com',
		:type_name => 'MSN'
	}
]

ContactWay::Im.create! [ {
		:customer_id => Customer.first.id,
		:way => 'liuxiaoming.blog.com',
		:type_name => '博客'
	}, {
		:customer_id => Customer.first.id,
		:way => 'liuxiaoming.weibo.com',
		:type_name => '微博'
	}, {
		:customer_id => Customer.all[1].id,
		:way => 'chenzhen.blog.com',
		:type_name => '博客'
	}, {
		:customer_id => Customer.first.id,
		:way => 'chenzhen.weibo.com',
		:type_name => '微博'
	}
]

ContactRecord.create! [ {
    :customer_id => Customer.first.id ,
    :content => '再次电话沟通中得知对方已经出差，需要10天左右时间才能回来:_(',
    :contacted_on => 1.days.ago,
    :recorded_by_id => User.current_id
  },{
    :customer_id => Customer.first.id ,
    :content => '电话中达成了初步意向，但客户要求能够提前提车，同时价格上要有10%的优惠.看得出来客户对该款车辆相当感兴趣，双方沟通非常愉快：） ',
    :contacted_on => 3.days.ago,
    :recorded_by_id =>User.current_id
  },{
    :customer_id => Customer.all[1].id ,
    :content => '再次电话沟通中得知对方已经出差，需要10天左右时间才能回来:_(',
    :contacted_on => 1.days.ago,
    :recorded_by_id => User.current_id
  },{
    :customer_id => Customer.all[1].id ,
    :content => '电话中达成了初步意向，但客户要求能够提前提车，同时价格上要有10%的优惠.看得出来客户对该款车辆相当感兴趣，双方沟通非常愉快：） ',
    :contacted_on => 3.days.ago,
    :recorded_by_id => User.current_id
  }
]

Project.create! [ {
    :enterprise_id => Enterprise.first.id,
    :name => '宏海大厦',
    :address => '海口市海甸二东路'
  }, {
    :enterprise_id => Enterprise.first.id,
    :name => '海悦国际',
    :address => '海口市海甸五西路31号'
  }, {
    :enterprise_id => Enterprise.first.id,
    :name => '时代雅居',
    :address => '海口市金牛路1号'
  }
]